import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import {applyMiddleware, createStore } from 'redux';
import { createLogger } from 'redux-logger';
import { connect, Provider } from 'react-redux'
import { Reducers } from './reducers'
import { actions } from './action'
import fetch from 'dva/fetch';

class THUNK extends Component { 

    constructor(porps) {
        super(porps);
        const { dispatch } = this.props.store;
        
        dispatch(getListAction("1231"));
        this.props.store.dispatch(getListAction("1231")).then(() => console.log("121212", this.props.store.getState()));
        console.log(this.props.store.getState());
    }


    componentDidMount() { 


        // fetch('http://localhost:40301/api/Default1/Feach', {
        //     body: JSON.stringify({ username: "123", password: "456" }),
        //     method: 'post',
        //     headers: {
        //         'content-type': 'application/json'
        //     }
        // })
        //     .then(res => res.text())
        //     .then(res => console.log(res));
        //dispatch(getListAction("1231"));
    }

    render() {
        return <></>;
     }

}


const getListAction = (one) => {
    return (dispatch, getState) => {
        dispatch(actions[0]);
        //此处加return可以让 dispatch 返回原方法 列如：dispatch(fetch()).then
        return  fetch('http://localhost:40301/api/Default1/Feach', {
            body: JSON.stringify({ username: "123", password: "456" }),
            method: 'post',
            headers: {
                'content-type': 'application/json'
            }
        })
            .then(res => res.text())
            .then(res => {
                console.log(one)
                console.log(res)
                actions[6].data = res;
                dispatch(actions[6]);
            });

    }
}


export default THUNK;





